Add stub for AsyncExitContext added by bpo-29302.#1876
Add stub for AsyncExitContext added by bpo-29302.#1876JelleZijlstra merged 5 commits intopython:masterfrom
Conversation
stdlib/2and3/contextlib.pyi
Outdated
| def __enter__(self: _U) -> _U: ... | ||
|
|
||
| if sys.version_info >= (3, 7): | ||
| from asyncio.futures import Future |
There was a problem hiding this comment.
Why not use typing.Awaitable instead of Future?
There was a problem hiding this comment.
I was looking at stubs for asyncio.tasks as an example.
On the second look I agree, Awaitable should be used instead.
stdlib/2and3/contextlib.pyi
Outdated
| *args: Any, **kwds: Any) -> Callable[..., None]: ... | ||
| def push_async_callback(self, callback: _CallbackCoroFunc, | ||
| *args: Any, **kwds: Any) -> _CallbackCoroFunc: ... | ||
| def pop_all(self) -> ExitStack: ... |
There was a problem hiding this comment.
Should return AsyncExitStack.
There was a problem hiding this comment.
Actually, I think it should be implemented as __enter__ / __aenter__: pop_all instantiates type(self).
Probably that should also be fixed for ExitStack.
There was a problem hiding this comment.
Thanks! Would you mind fixing it there too while you're at it?
| def pop_all(self) -> ExitStack: ... | ||
| def aclose(self) -> Awaitable[None]: ... | ||
| def __enter__(self: _U) -> _U: ... | ||
| def __aenter__(self: _U) -> Awaitable[_U]: ... |
There was a problem hiding this comment.
Do you not need __exit__ and __aexit__? I suppose the base class provides those.
There was a problem hiding this comment.
Base class implementations should be enough.
There was a problem hiding this comment.
Actually, that's true for __aexit__ but not __exit__.
There was a problem hiding this comment.
Or do you mean that's because AsyncContextManager does not inherit from ContextManager?
There was a problem hiding this comment.
Oh, nvm. There is no __enter__ for AsyncExitStack.
|
@JelleZijlstra Should I squash into 2 commits: one for AsyncExitStack and one for ExitStack's bugfix? |
|
No, that's fine. I'll squash when I merge (which I will do as soon as CI passes). |
Stub for changes added to Python 3.7 in python/cpython#4790.